package com.sm.honkon.app.ext

import android.annotation.SuppressLint
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.view.View
import android.widget.RadioButton
import android.widget.TextView
import androidx.databinding.BindingAdapter
import cos.mos.sb.widget.KBubbleSeekBar

object DataAdapter {

    @BindingAdapter(value = ["drawStartWithBounds", "bounds"], requireAll = false)
    @JvmStatic
    fun drawStartWithBounds(view: TextView, drawStart: Drawable, bounds: Int = 50) {
        drawStart.setBounds(0, 0, bounds, bounds)
        view.setCompoundDrawables(drawStart, null, null, null)
    }

    @BindingAdapter(value = ["progress"])
    @JvmStatic
    fun setProgress(view: KBubbleSeekBar, progress: Float) {
        if (progress >= view.min)
            view.setProgress(progress)
    }

    @BindingAdapter(value = ["setSelect"])
    @JvmStatic
    fun setSelect(view: View, select: Boolean) {
        view.isSelected = select
    }
    @BindingAdapter(value = ["drawEndWithBounds2", "bounds"], requireAll = true)
    @JvmStatic
    fun drawEndWithBounds2(view: TextView, drawStart: Drawable, bounds: Int = 50) {
        drawStart.setBounds(0, 0, bounds, bounds)
        view.setCompoundDrawables(null, null, drawStart, null)
    }

    @BindingAdapter(value = ["drawEndWithBounds"])
    @JvmStatic
    fun drawEndWithBounds(view: TextView, drawStart: Drawable) {
        drawStart.setBounds(0, 0, 50, 50)
        view.setCompoundDrawables(null, null, drawStart, null)
    }

    @BindingAdapter(value = ["required"])
    @JvmStatic
    fun required(view: TextView, text: String) {
        val span = SpannableString("*$text");
        span.setSpan(ForegroundColorSpan(Color.RED), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        view.text = span;

    }
}
